<template>
  <div>
    <div class="back">
      <van-nav-bar
        title="登录"
        left-text=""
        left-arrow
        @click-left="onClickLeft"
      />
      <div class="title">欢迎登录cdf海南免税</div>
      <div class="title1">未注册手机号验证后自动创建cdf海南免税账户</div>
    </div>

    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="loginname"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="oldpassword"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请输入密码' }]"
        v-if="bool"
      />
      <div v-else>
        <van-field
          v-model="oldpassword"
          type="text"
          name="密码"
          label="旧密码"
          placeholder="旧密码"
          :rules="[{ required: true, message: '旧密码' }]"
        />

        <van-field
          v-model="newpassword"
          type="text"
          name="密码"
          label="新密码"
          placeholder="新密码"
          :rules="[{ required: true, message: '新密码' }]"
        />
      </div>
      <div class="footer">
        <input type="checkbox" @click="change" />
        <span>我已阅读并同意</span>
        <span>《用户服务协议》、</span>
        <span>《隐私政策》，</span>
        <span>并授权cdf海南免税使用该cdf海南免税账号信息进行统一管理。</span>
      </div>
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >登录</van-button
        >
      </div>
    </van-form>
    <span class="two"><router-link to="/zhuce">手机快速注册</router-link></span>
    <p class="three" @click="bool = !bool">
      {{ bool ? "点我修改密码" : "返回登录" }}
    </p>
  </div>
</template>

<script>
import service from "../../../utils/service";
import { Dialog } from "vant";
import { Toast } from "vant";
export default {
  data() {
    return {
      username: "",
      password: "",
      oldpassword: "",
      newpassword: "",
      bool: "true",
    };
  },
  methods: {
    onClickLeft() {
      this.$router.push("/home");
    },
    onSubmit(values) {
      console.log("submit", values);
      service({
        url: "http://118.178.238.19:3001/api/user/login",
        method: "post",
        data: {
          loginname: values.loginname,
          password: values.password,
        },
      }).then((res) => {
        console.log(res);
        // window.sessionStorage.setItem("token",res.data.data.token)
        // this.$router.push("/")
        if (res.data.code == 200) {
          Dialog.alert({
            title: "登录",
            message: "恭喜你登录成功!!",
          });
          console.log(res);
          window.sessionStorage.setItem("token", res.data.data.token);
          window.sessionStorage.setItem("userid", res.data.data.user);
          this.$router.push("/");
        }
      });
    },
    change() {
      this.status = !this.status;
    },
  },
};
</script>

<style scoped>
.one {
  text-align: center;
  color: #666;
  font-size: 20px;
  margin-top: 5px;
}
.two {
  font-size: 12px;
  margin-left: 300px;
}
.van-button--round {
  background-color: tomato;
  border: 0;
}
.back {
  background-image: url("https://m.cdfgsanya.com/wap/resources/images/bar-bg@2x.5691a9a5.png")
    no-repeat 0 0;
  background-size: 100% auto;
}
.zi {
  margin-left: 100px;
}

.title {
  font-size: 24px;
  font-weight: 300;
  margin-top: 50px;
  margin-bottom: 10px;
  margin-left: 20px;
}
.title1 {
  font-size: 12px;
  color: rgba(165, 157, 157, 0.708);
  margin-left: 20px;
}
.hezi {
  margin-top: 20px;
  display: flex;
  justify-content: space-between;
  margin-bottom: 30px;
}
.hezi span {
  color: red;
  font-size: 12px;
}
.footer {
  width: 100%;
  /* position: fixed;
        bottom: 30px; */
}
input {
  width: 15px;
  height: 15px;
  border-radius: 9px;
}
.footer span {
  font-size: 12px;
  margin-left: 10px;
}
.footer span:nth-child(3) {
  color: red;
}
.footer span:nth-child(4) {
  color: red;
}
.footer input {
  margin-left: 10px;
}
.block {
  width: 100%;
  height: 40px;
  margin-top: 20px;
  font-size: 14px;
  color: white;
}
.block input {
  width: 100%;
  height: 40px;
  border: none;
  border-bottom: 1px solid gainsboro;
}
</style>